package com.example.wastes.orderPruduct.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wastes.articles.mapper.ArticlesMapper;
import com.example.wastes.common.pojo.Articles;
import com.example.wastes.common.pojo.Order;
import com.example.wastes.common.pojo.OrderPruduct;
import com.example.wastes.order.mapper.OrderMapper;
import com.example.wastes.orderPruduct.mapper.OrderPruductMapper;
import com.example.wastes.orderPruduct.service.OrderPruductService;
import com.example.wastes.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderPruductServiceImpl extends ServiceImpl<OrderPruductMapper, OrderPruduct> implements OrderPruductService {
    @Autowired
    private OrderPruductMapper orderPruductMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ArticlesMapper articlesMapper;
    @Autowired
    private OrderMapper orderMapper;
    //那个用户下了那个订单，卖的那个东西，这个东西卖了多少
    public void sumprice(int uid,int oid,int aid,int number){
        Double s = orderPruductMapper.sumoid(oid);
        Order order =new Order();
        order.setTotal(s);
        orderMapper.insert(order);
        Articles articlesrice = articlesMapper.selectid(aid);
        Double a =articlesrice.getMoney();
        Double moneys =number * a;
        OrderPruduct orderPruduct = new OrderPruduct();
        orderPruduct.setMoneys(moneys);
        orderPruduct.setUid(uid);
        orderPruduct.setOid(oid);
        orderPruduct.setAid(aid);
        orderPruduct.setNumber(number);
       orderPruductMapper.insert(orderPruduct);
    }

    @Override
    public List<OrderPruduct> findAllOP(Integer id) {
        return orderPruductMapper.findAllOP(id);
    }
}
